package com.javaIO.demo2;

import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException {
        /**
         * 字符流:对字节流的包装  文本文件 优先使用 编码和解码
         */

        FileOutputStream outputStream = new FileOutputStream("D:\\SoftDevelopment\\Java\\file\\test.txt");

        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);

        outputStreamWriter.write("华为666666");

        outputStreamWriter.close();
        System.out.println("---------------------------------");

        FileInputStream inputStream = new FileInputStream("D:\\SoftDevelopment\\Java\\file\\test.txt");
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
        char[] chars = new char[1024];
        int len;
        while ((len = inputStreamReader.read(chars)) != -1) {
            System.out.println(new String(chars, 0, len));
        }
        inputStreamReader.close();
    }
}
